package com.pmsystem.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.pmsystem.interceptor.AdministratorInterceptor;
import com.pmsystem.interceptor.RootInterceptor;
import com.pmsystem.interceptor.UserInterceptor;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.pmsystem.controller")
public class WebConfig implements WebMvcConfigurer {
	
	@Autowired
	private RootInterceptor rootInterceptor;
	@Autowired
	private AdministratorInterceptor administratorInterceptor;
	@Autowired
	private UserInterceptor userInterceptor;
	@Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/",".html");
	}
    @Override
	public void addInterceptors(InterceptorRegistry registry) {
//		registry.addInterceptor(rootInterceptor).addPathPatterns("/root/**").excludePathPatterns("/root/login*");
//		registry.addInterceptor(administratorInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login*");
		registry.addInterceptor(userInterceptor).addPathPatterns("/user/**").excludePathPatterns("/user/login*","/user/regist");
	}
    
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//    	registry.addResourceHandler("/Information/**")
//        .addResourceLocations("/Information/js")
//        .setCachePeriod(31556926);
//    }
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    	WebMvcConfigurer.super.configureContentNegotiation(configurer);
    }
}
